import { request } from '@/utils/request'

enum API {
  SECKILL_SESSION_LIST_URL = '/api/coupon/seckillsession/list',
  SECKILL_SKU_RELATION_LIST_URL = '/api/coupon/seckillskurelation/list',
  SECKILL_SESSION_DELETE_URL = '/api/coupon/seckillsession/delete',
  SECKILL_SKU_RELATION_DELETE_URL = '/api/coupon/seckillskurelation/delete',
  SECKILL_SESSION_INFO_URL = '/api/coupon/seckillsession/info',
  SECKILL_SKU_RELATION_INFO_URL = '/api/coupon/seckillskurelation/info',
  SECKILL_SESSION_UPDATE_COMMIT = '/api/coupon/seckillsession',
  SECKILL_SKU_RELATION_UPDATE_COMMIT = '/api/coupon/seckillskurelation',
}

export const reqSeckillSessionList = (
  page: number,
  limit: number,
  key: string,
) =>
  request.get<any, any>(
    API.SECKILL_SESSION_LIST_URL + `?page=${page}&limit=${limit}&key=${key}`,
  )

export const reqSeckillSessionDelete = (id: any) =>
  request.post<any, any>(API.SECKILL_SESSION_DELETE_URL, id)

export const reqSeckillSkuRelationDelete = (id: any) =>
  request.post<any, any>(API.SECKILL_SKU_RELATION_DELETE_URL, id)

export const reqSeckillSessionInfo = (id: number) =>
  request.get<any, any>(API.SECKILL_SESSION_INFO_URL + `/${id}`)

export const reqSeckillSkuRelationInfo = (id: number) =>
  request.get<any, any>(API.SECKILL_SKU_RELATION_INFO_URL + `/${id}`)

export const reqSeckillSkuRelationList = (
  page: number,
  limit: number,
  key: string,
  promotionSessionId: number,
) =>
  request.get<any, any>(
    API.SECKILL_SKU_RELATION_LIST_URL +
      `?page=${page}&limit=${limit}&key=${key}&promotionSessionId=${promotionSessionId}`,
  )

// UPDATE提交
export const reqSeckillSessionUpdateCommit = (
  type: string,
  id: number,
  name: string,
  startTime: string,
  endTime: string,
  status: string,
  createTime: Date,
) => {
  if (type == 'save') {
    return request.post<any, any>(
      API.SECKILL_SESSION_UPDATE_COMMIT + `/${type}`,
      {
        name,
        startTime,
        endTime,
        status,
        createTime,
      },
    )
  } else {
    return request.post<any, any>(
      API.SECKILL_SESSION_UPDATE_COMMIT + `/${type}`,
      {
        id,
        name,
        startTime,
        endTime,
        status,
        createTime,
      },
    )
  }
}

export const reqSeckillSkuRelationUpdateCommit = (
  type: string,
  id: number,
  promotionId: string,
  sessionId: number,
  skuId: string,
  seckillPrice: number,
  seckillCount: number,
  seckillLimit: number,
  seckillSort: number,
) => {
  if (type == 'save') {
    return request.post<any, any>(
      API.SECKILL_SKU_RELATION_UPDATE_COMMIT + `/${type}`,
      {
        promotionId,
        sessionId,
        skuId,
        seckillPrice,
        seckillCount,
        seckillLimit,
        seckillSort,
      },
    )
  } else {
    return request.post<any, any>(
      API.SECKILL_SKU_RELATION_UPDATE_COMMIT + `/${type}`,
      {
        id,
        promotionId,
        sessionId,
        skuId,
        seckillPrice,
        seckillCount,
        seckillLimit,
        seckillSort,
      },
    )
  }
}
